package com.xinghou.platform.dao.main.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import com.xinghou.platform.dao.bases.JdbcTemplate;
import com.xinghou.platform.dao.bases.database.CustomerContextHolder;
import com.xinghou.platform.model.main.UserInfo;

/**
 * 
 * @author wzk
 * 
 */
@Service
public class UserInfoDAOImpl  {/*
	@Resource
	private JdbcTemplate jdbcTemplate;

	@Override
	public UserInfo getUserInfoById(Integer userInfoId) throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql = "SELECT Info_id,Nick_name,Birthday,Signature,Head_id,Create_time,Update_time,Reg_status FROM user_info WHERE Info_id=?";
		UserInfo userinfo = jdbcTemplate.queryForObject(sql,new Object[] { userInfoId }, new UserInfoMapper());
		CustomerContextHolder.clearCustomerType();
		return userinfo;
	}

	@Override
	public int updateUserInfo(UserInfo userinfo) throws DataAccessException {
		StringBuffer strSQL = new StringBuffer(
				"UPDATE user_info SET Info_id=?,Nick_name=?,Birthday=?,Signature=?,Head_id=?,Create_time=?,Reg_status=? WHERE Info_id=?");
		Object[] params = { userinfo.getInfoId(),userinfo.getNickName(),userinfo.getBirthday(),userinfo.getSignature(),
			userinfo.getHeadId(),userinfo.getCreateTime(),userinfo.getRegStatus(),userinfo.getInfoId() };
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
		int ret = jdbcTemplate.update(strSQL.toString(), params);
		CustomerContextHolder.clearCustomerType();
		return ret;
	}

	@Override
	public int saveUserInfo(UserInfo userinfo) throws DataAccessException {
		String sql = "INSERT INTO user_info (Nick_name,Birthday,Signature,Head_id,Create_time,Update_time,Reg_status) VALUES (?,?,?,?,?,?,?)";
		Object[] params = {userinfo.getNickName(),
				userinfo.getBirthday(), userinfo.getSignature(),
				userinfo.getHeadId(), userinfo.getCreateTime(),
				userinfo.getUpdateTime(),userinfo.getRegStatus() };
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
		int ret = jdbcTemplate.save(sql.toString(),params);
		CustomerContextHolder.clearCustomerType();
		return ret;
	}

	@Override
	public List<UserInfo> getUserInfoList(Integer frompage) throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql="SELECT Info_id,Nick_name,Birthday,Signature,Head_id,Create_time,Update_time,Reg_status FROM user_info LIMIT ?,10";
		List<UserInfo> UserInfoList=jdbcTemplate.query(sql,new Object[] {frompage}, new UserInfoMapper());
		return UserInfoList;
	}
	
	private static final class UserInfoMapper implements RowMapper<UserInfo> {
		public UserInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
			UserInfo userinfo = new UserInfo();
			userinfo.setInfoId(rs.getInt("Info_id"));
			userinfo.setNickName(rs.getString("Nick_name"));
			userinfo.setBirthday(rs.getTimestamp("Birthday"));
			userinfo.setSignature(rs.getString("Signature"));
			userinfo.setHeadId(rs.getInt("Head_id"));
			userinfo.setCreateTime(rs.getTimestamp("Create_time"));
			userinfo.setUpdateTime(rs.getTimestamp("Update_time"));
			userinfo.setRegStatus(rs.getInt("Reg_status"));
			return userinfo;
		}
	}
	
	public List<UserInfo> getUserInfoList(Integer frompage, int type, String key)
			throws DataAccessException {
		key = "%"+key+"%";
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql="SELECT a.Info_id,a.Nick_name,a.Birthday,a.Signature,a.Head_id,a.Create_time,a.Update_time,a.Reg_status "
				+ "FROM user_info a, USER b WHERE b.User_type = 0 AND a.Info_id = b.Info_id AND Nick_name LIKE ? LIMIT ?,10";
		List<UserInfo> UserInfoList=jdbcTemplate.query(sql,new Object[] {key,frompage}, new UserInfosMapper());
		return UserInfoList;
	}
	
	private static final class UserInfosMapper implements RowMapper<UserInfo> {
		public UserInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
			UserInfo userinfo = new UserInfo();
			userinfo.setInfoId(rs.getInt("a.Info_id"));
			userinfo.setNickName(rs.getString("a.Nick_name"));
			userinfo.setBirthday(rs.getTimestamp("a.Birthday"));
			userinfo.setSignature(rs.getString("a.Signature"));
			userinfo.setHeadId(rs.getInt("a.Head_id"));
			userinfo.setCreateTime(rs.getTimestamp("a.Create_time"));
			userinfo.setUpdateTime(rs.getTimestamp("a.Update_time"));
			userinfo.setRegStatus(rs.getInt("a.Reg_status"));
			return userinfo;
		}
	}*/
}
